home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / CD CHIP.ISO / WebServ / server7 / bin / db.dpr < prev    next >
Encoding:
Text File  |  1996-07-29  |  3.4 KB  |  154 lines

  1. library db;
  2.  
  3. uses
  4.   Windows, SysUtils,
  5.   Classes,
  6.   Httpext,
  7.   ISAPISock, DBTables;
  8.  
  9.  
  10.  
  11. //
  12. // Called anytime a GET is performed on this DLL
  13. //
  14. procedure ProcessGet(sock: TISAPISock);
  15. begin
  16.  with sock do
  17.  begin
  18.    // Blast out a header
  19.    Writeln('HTTP/1.0 200 OK');
  20.    Writeln('Content-type: text/html');
  21.    Writeln('Expires: 0');
  22.    Writeln('');
  23.  
  24.    HHeader('Database: EMPLOYEE.db', hcGray, hcBlack, hcBlue);
  25.    HPageStart;
  26.  
  27.    HHeading(1, 'Search database...');
  28.  
  29.    // Enter an employee ID
  30.    HFormStart('POST', '/bin/db.dll');
  31.    HLine('Valid Employee IDs are 2,4,8,9...');
  32.    HEditbox('Employee ID:', 'EmpID', '', 15, 15);
  33.    HFormEnd('Submit', 'Clear');
  34.  
  35.    HPageEnd;
  36.  end;
  37. end;
  38.  
  39.  
  40. procedure ProcessPost(sock: TISAPISock);
  41. var
  42.   dBase: TTable;
  43.   i: Integer;
  44.   s: String;
  45. begin
  46.  with sock do
  47.  begin
  48.    // Blast out a header
  49.    Writeln('HTTP/1.0 200 OK');
  50.    Writeln('Content-type: text/html');
  51.    Writeln('Expires: 0');
  52.    Writeln('');
  53.  
  54.    HHeader('Database: EMPLOYEE.db', hcGray, hcBlack, hcBlue);
  55.    HPageStart;
  56.    dBase:=TTable.Create(nil);
  57.    try
  58.      try
  59.        dBase.Active:=False;
  60.        // This DB and alias are included with the Delphi
  61.        // demo.
  62.        dBase.DatabaseName:='DBDEMOS';
  63.        dBase.TableName:='EMPLOYEE.DB';
  64.        dBase.Active:=True;
  65.  
  66.        HFormStart('POST', '/bin/db.dll');
  67.        HLine('Valid Employee IDs are 2,4,8,9...');
  68.        HEditbox('Employee ID:', 'EmpID', '', 15, 15);  
  69.        HFormEnd('Submit', 'Clear');
  70.  
  71.        if dBase.FindKey([ GetFormVal('EmpID') ]) then
  72.        begin
  73.          // find key found what we were looking for. Spill this
  74.          // record to the browser
  75.          HSeparator;
  76.          HHeading(1, 'Record located...');
  77.          HSeparator;
  78.  
  79.          // Iterate through field names
  80.          for i:=0 to dBase.FieldCount-1 do
  81.          begin
  82.            s:=dBase.Fields[i].DisplayLabel+': '+dBase.Fields[i].AsString;
  83.            HLine( s );
  84.          end
  85.        end  
  86.        else
  87.        begin
  88.          // Find key didn't work
  89.          HHeading(1, 'Record not found! Database: EMPLOYEE.db');
  90.        end;  
  91.      finally
  92.        dBase.Free;
  93.      end;  
  94.    except
  95.      HLine('An error occurred reading the database');
  96.    end;
  97.    HPageEnd;
  98.  end;
  99. end;
  100.  
  101. // CASE MATTERS FOR THIS FUNCTION NAME
  102. function GetExtensionVersion(var ver: THSE_VERSION_INFO): Boolean; stdcall;
  103. begin
  104.   result:=True;
  105. end;
  106.  
  107. // CASE MATTERS FOR THIS FUNCTION NAME
  108. function HttpExtensionProc(var ecb: TEXTENSION_CONTROL_BLOCK): LongInt; stdcall;
  109. var
  110.   sock: TISAPISock;
  111.   method: String;
  112. begin
  113.   try
  114.     // Create the socket helper
  115.     sock:=TISAPISock.Create(ecb);
  116.  
  117.     method:=sock.GetServerVariable('REQUEST_METHOD');
  118.     //SetLength(method, 3);
  119.     //method:='GET';
  120.     if method='GET' then
  121.       ProcessGet(sock)
  122.     else if method='POST' then
  123.       ProcessPost(sock)
  124.     else
  125.     begin
  126.       sock.Writeln('HTTP/1.0 200 OK');
  127.       sock.Writeln('Content-type: text/html');
  128.       sock.Writeln('');
  129.       sock.Writeln('Unknown method was: '+method+'.');
  130.     end;
  131.  
  132.  
  133.     // Return a normal status code
  134.     StrLCopy( ecb.lpszLogData, PChar('DLL Finished with no errors'), HSE_LOG_BUFFER_LEN-1);
  135.     Result:=HSE_STATUS_SUCCESS;
  136.  
  137.     // Free the socket
  138.     sock.Free;
  139.   except
  140.     ;
  141.   end;
  142. end;
  143.  
  144. // * REQUIRED FOR DYNAMIC BINDING.
  145. // * Index values aren't need.
  146. // * Case doesn't matter here.
  147. exports
  148.   GetExtensionVersion,
  149.   HttpExtensionProc;
  150.  
  151. begin
  152. end.
  153.  
  154.